package com.skymxc.clickroute;

import android.app.Activity;
import android.util.Log;
import android.view.View;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * <p>
 *
 * </p>
 *
 * @author 孟祥超
 * <p>
 * date: 2021/8/9
 */
public class OnLongClickWrap implements View.OnLongClickListener {
    public static final String TAG = "OnLongClickWrap";
    private Method method;
    private Activity activity;

    public OnLongClickWrap(Method method, Activity activity) {
        this.method = method;
        this.activity = activity;
    }


    @Override
    public boolean onLongClick(View v) {
        if (null!=activity && null!=method){
            try {
                Log.i(TAG, "onLongClick: 反射调用");
                Object invoke = method.invoke(activity, v);
                return (boolean) invoke;
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
        return false;
    }
}
